﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Model;
using Model.Entities;
using MusicSite.ViewClasses;

namespace MusicSite.Views.Content.Collection
{
    public partial class IndexCollect : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckAuthentication();
            UserRole roleId = (UserRole)(Session["UserRole"]);
            switch (roleId)
            {
                case UserRole.Administrator:
                    break;
                case UserRole.Registrator:
                    HyperLink admLink1 = (HyperLink)Master.FindControl("adminLink");
                    admLink1.Visible = false;
                    break;
                case UserRole.User:
                    HyperLink admLink = (HyperLink)Master.FindControl("adminLink");
                    admLink.Visible = false;
                    break;
                default:
                    break;
            }
            var albumProv = new AlbumProvider();
            var allAlbums = albumProv.GetAlbums();
            RepeaterAlbum.DataSource = allAlbums;   
            RepeaterAlbum.DataBind();
            
            for (int i = 0; i < allAlbums.Count; i++)
            {
                var tracksRepeater = (Repeater) RepeaterAlbum.Items[i].FindControl("TracksRepeater");
               
                tracksRepeater.DataSource = allAlbums[i].Tracks;
                tracksRepeater.DataBind();
            }
        }

        public List<TrackDetails> GetTracksForEachAlbum(AlbumDetails alb)
        {
            return alb.Tracks;
        }
    }
}
